const Joi = require('joi')

// member模块验证规则 
// 新增
const addMemberSchema = Joi.object({
    name: Joi.string().alphanum().min(1).max(30).required(),
    credential_type: Joi.string().pattern(/^(id)|(drive)$/).required(),
    credential_no: Joi.string().min(1).max(400).required(),
    gender: Joi.string().pattern(/^(male)|(female)$/).required(),
    birthday: Joi.date().required(),
    job: Joi.string().min(1).max(400).required(),
    level: Joi.string().min(1).max(400).required(),
    salary: Joi.number().required(),
    join_date: Joi.date().required(),
    record_user: Joi.string().min(1).max(400).required(),
    update_user: Joi.string().min(1).max(400).required(),
    // phone: Joi.string().pattern(/^[0-9]{0,5}[-]{0,1}[0-9]{5,12}$/),
    phone: Joi.string().min(0),
    // email: Joi.string().email({minDomainSegments: 2, tlds: {allow: ['com', 'net']}}),
    email: Joi.string().min(0),
    state: Joi.boolean(),
    introduction: Joi.string().min(0).max(100000)  
})

// 分页查询 
const memberListSchema = Joi.object({
    pageSize: Joi.number(),
    currentPage: Joi.number(),
    where: Joi.object(),
    sort: Joi.object() 
})

// 删除  
const memberDeleteSchema = Joi.object({
    ids: Joi.array() 
})

// 更新 
const memberUpdateSchema = Joi.object({
    id: Joi.number().required(),
    name: Joi.string().alphanum().min(1).max(30),
    credential_type: Joi.string().pattern(/^(id)|(drive)$/),
    credential_no: Joi.string().min(1).max(400),
    gender: Joi.string().pattern(/^(male)|(female)$/),
    birthday: Joi.date(),
    job: Joi.string().min(1).max(400),
    level: Joi.string().min(1).max(400),
    salary: Joi.number(),
    join_date: Joi.date(),
    record_user: Joi.string().min(1).max(400),
    update_user: Joi.string().min(1).max(400),
    // phone: Joi.string().pattern(/^[0-9]{0,5}[-]{0,1}[0-9]{5,12}$/),
    phone: Joi.string().min(0),
    // email: Joi.string().email({minDomainSegments: 2, tlds: {allow: ['com', 'net']}}),
    email: Joi.string().min(0),
    state: Joi.boolean(),
    introduction: Joi.string().min(0).max(100000)  
})





exports.addMember = addMemberSchema 
exports.memberList = memberListSchema 
exports.memberDelete = memberDeleteSchema 
exports.memberUpdate = memberUpdateSchema 
